#include <iostream>
using namespace std;

class A {
	int *p;
	
public:
	A(int i) { 
		cout << "Constructor" << endl; 
		p = new int(i); 
	}
	
	~A() { 
		cout << "Destructor" << endl; 
		delete p; 
	}
	
	A(const A &r) //copy consructor
	{ 
		cout << "Copy-constructor" << endl; 
		p=new int(*r.p); 
	}
	
	A& operator=(const A& r); //assignment
	
	void output() { cout << p << "->" << *p << endl; }
	
};

A& A::operator=(const A& r) //assignment
{
	cout << "Assignment" << endl;
	
	if (this==&r) return *this; // self-assignment: r=r
	
	delete p;
	
	p=new int(*r.p);
	
	return *this; 
}

int main(int argc, char *argv[]) {
	/*
		new/new[] 会返回一个指向该对象的指针
		new 出来的对象，只能通过delete销毁
	*/
	
	/*
		语法：
			MyType *fp = new MyType(1,2);
			delete fp; 
	
			MyType *fp = new MyType[100]; 
			delete [] fp;
	*/
	
}